package chaoyue.study.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 使用配置的方式定义路由规则
 */
@Configuration
public class GatewayConfig {
    /**
     * 使用api的方式创建一个路由配置
     * RouteLocatorBuilder 容器中本来就有，可以用来构建RouteLocator
     */
    @Bean
    public RouteLocator myRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("bd_route", ps -> ps.path("/a").uri("https://baidu.com"))
                .route("tb_route", ps -> ps.path("/b").uri("https://taobao.com"))
                .route("jd_route", ps -> ps.path("/c").uri("https://jd.com"))
                .build();
    }
}
